package demo1;

public class Test {
    // 2. 方法传参：形参为父类型引用，可以接收任意子类的对象
    public static void func(Animal animal){

    }

    // 3. 作返回值：返回任意子类对象
    public static Animal func2(){
        Dog dog=new Dog("mingming",10);
        return dog;
    }
    public static void main1(String[] args) {
        Animal animal=new Dog("LILI",10);// 1. 直接赋值：子类对象赋值给父类对象
        animal.eat();
        Dog dog=new Dog("mingming",10);
        func(dog);
    }

    public static void main(String[] args) {
        Animal animal1=new Bird("mingming",10);
        Bird bird1=(Bird)animal1;
        bird1.fly();
        Animal animal2=new Dog("lili",10);
        if(animal2 instanceof Bird){
            Bird bird2=(Bird)animal2;
            bird2.fly();
        }else{
            System.out.println("animal2不是鸟");
        }
    }
    public static void main3(String[] args) {
        Animal animal=new Bird("mingming",10);
        Bird bird1=(Bird)animal;
        bird1.fly();
        Animal animal2=new Dog("lili",10);
        Bird bird2=(Bird)animal2;
        bird2.fly();
    }

}
